package tq.com.tqteacher.discuss.vh;

import android.support.v7.widget.RecyclerView;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;

import tq.com.tqteacher.model.TQCommentOverInfoModel;
import tq.com.tqteacher.model.TQLogin;

public abstract class TQDiscussViewHold extends RecyclerView.ViewHolder {
    protected IDiscussItemClickListener mIDiscussItemClickListener  = null;
    protected TQCommentOverInfoModel.TQCommentInfoModel mCommentInfoModel = null;

    public TQDiscussViewHold(View pView){
        super(pView);

        itemView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
            @Override
            public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
                if(mIDiscussItemClickListener == null
                        || mCommentInfoModel == null
                        || mCommentInfoModel.getUserInfo().getId() != TQLogin.getCurrent().getUserInfo().getId()){
                    return;
                }

//                createDeleteMenu(menu, v, menuInfo);
            }
        });
    }

    public void bindData(TQCommentOverInfoModel.TQCommentInfoModel pInfoModel){

    }

    public void setIDiscussItemClickListener(IDiscussItemClickListener pListener){
        mIDiscussItemClickListener = pListener;
    }

    protected boolean canDelete(){
        if(mIDiscussItemClickListener == null
                || mCommentInfoModel == null
                || mCommentInfoModel.getUserInfo().getId() != TQLogin.getCurrent().getUserInfo().getId()){
            return false;
        }
        return true;
    }

    protected void createDeleteMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo){
        menu.add("删除").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if(mIDiscussItemClickListener != null){
                    mIDiscussItemClickListener.deleteItem(mCommentInfoModel);
                }
                return false;
            }
        });
    }
}
